package com.machuxin.course.patterns.proxy.jdklib;

import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;

public class Test {

    public static void main(String[] args) {
        DynamicProxyHandler dynamicProxyHandler = new DynamicProxyHandler();
        BuyHouse proxyBuyHouse = (BuyHouse) dynamicProxyHandler.getInstance(new BuyHouseImpl());
        proxyBuyHouse.buyHouse();

        // 生成代理类
        byte[] bytes = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{BuyHouseImpl.class});
        try {
            FileOutputStream os = new FileOutputStream("E://$Proxy2.class");
            os.write(bytes);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
